<?php
/**
 * 用于抓取火币价格
 * User: liuser
 * Date: 2018/6/13
 * Time: 上午11:38
 */

#访问密钥
#9b1aef04-5245fe3b-a3227282-811aa

#私密密钥
#aee32876-284fbb84-67484b25-0140e

// 定义参数
define('ACCOUNT_ID', '18315801'); // 你的账户ID
define('ACCESS_KEY','9b1aef04-5245fe3b-a3227282-811aa'); // 你的ACCESS_KEY
define('SECRET_KEY', 'aee32876-284fbb84-67484b25-0140e'); // 你的SECRET_KEY
include "lib.php";
include  __DIR__."/../../DBPDO.php";


if(isset($argv[1])) {
    $pdo = new DBPDO();
    $symbol_list = [
        'btc',
        'bch',
        'etc',
        'ltc',
        'eos',
        'xrp',
        'omg',
        'dash',
        'zec',
        'iota',
        'ada',
        'steem',
        'cmt',
        'wicc',
        'soc',
        'ctxc',
        'act',
        'btm',
        'bts',
        'ont',
        'iost',
        'ht',
        'trx',
        'dta',
        'neo',
        'qtum',
        'stm',
        'ela',
        'ven',
        'theta','snt','zil','xem','nas','ruff','hsr','let','mds','storj','elf','itc','cvc','gnt'
    ];
    foreach($symbol_list as $item) {
        $sql = "INSERT INTO `coin_symbol`(`exchange_id`, `exchange_name`, `symbol`) 
                VALUES (1,'火币','{$item}usdt')";
        $pdo->execute($sql);
    }
    exit;


}


//实例化类库
$req = new \price\huobi\req();
$pdo = new DBPDO();
$res = $pdo->fetchAll("select symbol from coin_symbol where exchange_name = '火币'");
foreach ($res as $re) {
    $symbol = $re['symbol'];
    $klin_list = $req->get_history_kline($symbol,'1min');
    if($klin_list['status'] == 'ok')
    {
        $open = rtrim($klin_list['data'][0]['open'],0);
        $close = $klin_list['data'][0]['open'];
        $low = $klin_list['data'][0]['low'];
        $high = $klin_list['data'][0]['high'];
        $amount = $klin_list['data'][0]['amount'];
        $vol = $klin_list['data'][0]['vol'];
        $create_at = $klin_list['data'][0]['id'];
        $ins = "INSERT INTO  `coin_market`(`exchange_id`,`symbol`,`exchange_title`, `open`, `close`, `low`, `high`, `amount`, `vol`, `create_at`) 
                VALUES (1,'{$symbol}','火币','{$open}','{$close}','{$low}','{$high}','{$amount}','{$vol}',{$create_at})";
        echo $ins . PHP_EOL;
        $res = $pdo->execute($ins);
    }
}




